package com.java.multipledatasource.thread;

/**
 * @author hu
 * @version 1.0
 * @date 2021/1/15 0015 下午 10:11
 * @description
 */
public class ThreadTicket {

    static class  TicketThread implements  Runnable{

        private Integer count = 100;

        @Override
        public void run() {
            while (count > 0) {
                /**
                 * synchronized 不能 加 string 常量  Integer, Long
                 */
                synchronized (this) {
                    if (count > 0) {
                        System.out.println(Thread.currentThread().getName()  + "\t" + count--);
                        try {
                            Thread.sleep(1000);
                        } catch (InterruptedException e) {
                            e.printStackTrace();
                        }
                    }
                }
            }
        }
    }

    public static void main(String[] args) {
        TicketThread threadTicket = new TicketThread();
        new Thread(threadTicket, "t1").start();
        new Thread(threadTicket, "t2").start();
        new Thread(threadTicket, "t3").start();
    }
}
